<html lang="en">
<head>
    <title>积分商城管理</title>
    <#include "../common/header.ftl">
    <style>
        /*设置模态框中的图片铺满*/
        #showModal img{
            width: 100%;
        }
        /*当内容大于模态框时,会自定设置滚动条*/
        #showModal .modal-body{
            max-height: 600px;
            overflow-y: auto;
        }
    </style>

    <script>
        $(function () {
            //查看详情
            $('.lookBtn').click(function () {
                var id = $(this).data("id");
                $.get("/products/getContent.do", {productId:id} ,function (data) {
                    $("#showModal .modal-body").html(data.content);
                });
                $("#showModal").modal("show");
            })

            //取消上架
            $('.cancelBtn').click(function () {
                var id = $(this).data('id');
                var state = $(this).data('state');
                $.messager.confirm("温馨提示", "确定要取消上架吗", function () {
                    $.get("/products/changeState.do", {id:id, state:state}, function (data) {
                        if (data.success)
                            window.location.reload();
                        else
                            $.messager.alert(data.msg);
                    })
                })
            })

            //添加库存(modal)
            $('.addBtn').click(function () {
                var id = $(this).data("id");
                $("#addForm input[name='productId']").val(id);
                $('#addModal').modal('show');
            })
            //增加库存
            $('.saveBtn').click(function () {
                $.messager.confirm("温馨提示", "确定要添加库存吗", function () {
                    $('#addForm').ajaxSubmit(function (data) {
                        if (data.success)
                            window.location.reload();
                        else
                            $.messager.alert(data.msg);
                    })
                })
            })
            //推荐
            $('.recommendBtn').click(function () {
                var id = $(this).data('id');
                $.messager.confirm("温馨提示", "确定要推荐吗", function () {
                    $.get('/products/changeCommend.do', {id:id, isRecommend:1}, function (data) {
                        if (data.success)
                            window.location.reload();
                        else
                            $.messager.alert(data.msg);
                    })
                })
            })
        })
    </script>
</head>
<body>
<!--左侧菜单回显变量设置-->
<#assign currentMenu="creditShop_putaway">
<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-2">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-10">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">上架商品管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/products/putawayList.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label for="keyword">关键字:</label>
                    <input type="text" class="form-control" id="keyword" name="keyword" value="${qo.keyword!}"
                           placeholder="请输入商品名称" size="10">
                </div>
                <div class="form-group">
                    <label for="beginDate">上架日期:</label>
                    <input type="text" class="form-control dateInput" id="beginTime" name="beginTime" value="${(qo.beginTime?string("yyyy-MM-dd"))!}" placeholder="请输入起始时间" size="10" onfocus="WdatePicker()" readonly> ~
                </div>
                <div class="form-group">
                    <input type="text" class="form-control dateInput" id="endTime" name="endTime" value="${(qo.endTime?string("yyyy-MM-dd"))!}" placeholder="请输入截止时间" size="10" onfocus="WdatePicker()" readonly>
                </div>
                <div class="form-group">
                    <div class="">
                        商品类型:
                        <select class="form-control" id="type" name="type">
                            <option value="-1">--全部--</option>
                            <option value="0">服装</option>
                            <option value="1">食物</option>
                            <option value="2">住宿</option>
                            <option value="3">交通方式</option>
                            <option value="4">工具</option>
                            <option value="5">门票</option>
                            <option value="6">书籍</option>
                        </select>
                        <script>
                            $("#type").val(${qo.type});
                        </script>
                    </div>
                </div>
                <button id="btn_query" class="btn btn-info"><span class="glyphicon glyphicon-search"></span> 查询</button>
            </form>

            <table class="table table-striped table-hover" >
                <thead>
                    <tr>
                        <th>编号</th>
                        <th>商品名称</th>
                        <th>封面</th>
                        <th>积分消耗</th>
                        <th>上架时间</th>
                        <th>类型</th>
                        <th>销量</th>
                        <th>库存</th>
                    </tr>
                </thead>
               <#list result.list as entity>
                   <tr>
                       <td>${entity_index + 1}</td>
                       <td>${entity.name!}</td>
                       <td><img src="${entity.coverUrl!}" width="40px"></td>
                       <td>${(entity.price)!}</td>
                       <td>${(entity.putawayTime?string('yyyy-MM-dd'))!}</td>
                       <td>${entity.typeDisPlay!}</td>
                       <td>${(entity.productPlus.sale)!}</td>
                       <td>${(entity.productPlus.count)!}</td>
                       <td>
                           <a href="javascript:void(0);" class="btn lookBtn"  data-id="${entity.id!}">查看详情</a>
                           <a href="javascript:void(0);" class="btn recommendBtn"  data-id="${entity.id!}">推荐</a>
                           <a href="javascript:void(0);" class="btn addBtn"  data-id="${entity.id!}">添加库存</a>
                           <a href="javascript:void(0);" class="btn cancelBtn"  data-state="2" data-id="${entity.id!}">取消上架</a>
                       </td>
                   </tr>
               </#list>
            </table>
            <#include "../common/page.ftl">
        </div>
    </div>
</div>
<!---编辑--->
<div class="modal fade" id="showModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">查看内容</h4>
            </div>
            <div class="modal-body">

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal" >取消</button>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="addModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">添加库存</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/products/addCount.do" method="post" id="addForm">
                    <input type="hidden" value="" name="productId">

                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">添加数量：</label>
                        <div class="col-sm-6">
                            <input type="number" class="form-control"  name="count" value="" placeholder="请输入数量">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary saveBtn">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal" >取消</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>